package com.system.controller;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.alibaba.fastjson.JSON;
import com.system.service.FoodServiceImpl;
import com.system.service.IFoodService;
import com.system.util.PieChartData;

public class pieChartDataServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;

    public pieChartDataServlet() {
        super();
    }

	@SuppressWarnings("null")
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		response.setCharacterEncoding("utf-8");
		response.setContentType("text/html");
		request.setCharacterEncoding("utf-8");
		
		IFoodService foodService = new FoodServiceImpl();
		PieChartData pieChartData = foodService.pieChartData();
		
		PrintWriter out = response.getWriter();
		if (pieChartData != null) {
			pieChartData.setCode("1");
			out.print(JSON.toJSONString(pieChartData));
		}else {
			out.print("{\"code\":\"0\"}");
		}
		
	}

	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		doGet(request, response);
	}

}
